#include <iomanip>
#include <sstream>
#include "OpenSteer/SimpleVehicle.h"
#include "OpenSteer/OpenSteerDemo.h"
#include "OpenSteer/Color.h"
#include "ZombieSwarm.h"

#define NZOMBIES 30		// Zombies de la Swarm

//------------------------------------------------------------------------------
// ZombiePlugin

class ZombiePlugIn : public OpenSteer::PlugIn {

private:

	ZombieSwarm* _pZombieSwarm;

	Human* _pHuman;

	std::vector<ZombieSwarm*> _theVehicle;

	ProximityDatabase* _pd;

public:

const char* name(void) {return "Zombie Swarm";}

float selectionOrderSortKey (void) {return 0.06f;}

virtual ~ZombiePlugIn() {}

void open(void) {

	_pd = new OpenSteer::
		BruteForceProximityDatabase<OpenSteer::AbstractVehicle*> ();
	_pHuman = new Human;
	_pZombieSwarm =
		new ZombieSwarm(OpenSteer::Vec3(0, 0, 0), NZOMBIES, _pHuman, *_pd);

	_pHuman->setPosition(
		OpenSteer::randomVectorOnUnitRadiusXZDisk() * MAXDISTANCE);

	_theVehicle.push_back(_pZombieSwarm);
	OpenSteer::OpenSteerDemo::selectedVehicle = _pZombieSwarm;

	OpenSteer::OpenSteerDemo::init2dCamera(*_pZombieSwarm);
	OpenSteer::OpenSteerDemo::camera.setPosition (
		10, OpenSteer::OpenSteerDemo::camera2dElevation, 10);
	OpenSteer::OpenSteerDemo::camera.fixedPosition.set (40, 40, 40);
}

void update(const float currentTime, const float elapsedTime) {

	_pZombieSwarm->update(currentTime, elapsedTime);
	_pHuman->update(currentTime, elapsedTime);
}

void redraw(const float currentTime, const float elapsedTime) {

	_pZombieSwarm->draw();
	_pHuman->draw();

	OpenSteer::OpenSteerDemo::updateCamera(
		currentTime, elapsedTime, *_pZombieSwarm);

	OpenSteer::OpenSteerDemo::gridUtility(_pZombieSwarm->position());
}

void close (void) {

	_theVehicle.clear();
	delete(_pZombieSwarm);
	delete(_pHuman);
}

void reset (void) {

	_pZombieSwarm->reset();
	_pHuman->reset();
	_pHuman->setPosition(
		OpenSteer::randomVectorOnUnitRadiusXZDisk() * MAXDISTANCE);
}

const OpenSteer::AVGroup& allVehicles() {

	return (const OpenSteer::AVGroup&) _theVehicle;
}

};

ZombiePlugIn gZombiePlugIn;

